﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text;
using System.Windows.Data;
using System.Windows.Media.Imaging;

namespace WQDSkin.Core.Converters
{
    public class ByteToImageConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if(value != null)
            {
                BitmapImage bmi = new BitmapImage();
                bmi.BeginInit();
                MemoryStream ms = new MemoryStream((byte[])value);
                bmi.StreamSource = ms;
                bmi.EndInit();

                return bmi;
            }
            return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return value;
        }
    }
}
